package com.my.simple.web.controller.admin;

import com.my.simple.entity.dictionary.DictionaryOption;
import com.my.simple.service.dictionary.DictionaryService;
import com.my.simple.web.vo.ResponseData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping(value = "dictionary")
public class DictionaryController {
    private static final Logger LOGGER = LoggerFactory.getLogger(DictionaryController.class);
    private static final Integer USERID = 10000;
    @Autowired
    private DictionaryService dictionaryService;

    @GetMapping(value = "getoptionbytypeid/{typeid}")
    public ResponseEntity<ResponseData> getOptionByTypeId(@PathVariable("typeid") int typeId) {
        ResponseData responseData = new ResponseData();
        List<DictionaryOption> dictionaryOptionList = dictionaryService.getDictionaryOptionByTypeId(typeId);
        responseData.setData(dictionaryOptionList);
        ResponseEntity<ResponseData> responseEntity = new ResponseEntity<ResponseData>(responseData, HttpStatus.OK);
        return responseEntity;
    }

    @PostMapping(value = "adddictionaryoption")
    public ResponseEntity<ResponseData> addDictionaryOption(@RequestBody DictionaryOption option) {
        ResponseData responseData = new ResponseData();
        option.setUpdateBy(USERID);
        option.setUpdateDate(new Date());
        dictionaryService.addDictionaryOption(option);
        responseData.setMessage("add dictionary option successful");
        ResponseEntity<ResponseData> responseEntity = new ResponseEntity<ResponseData>(responseData, HttpStatus.OK);
        return responseEntity;
    }

}
